package ch.nostromo.tiffanys.engines;

import java.io.File;

import ch.nostromo.lib.controller.NosSettings;
import ch.nostromo.lib.controller.NosSettingsException;

public class EngineSettings extends NosSettings implements Cloneable {

  private static final long serialVersionUID = 1L;

  public static final int GAME_MODE_FIXED_DEPTH = 0;

  public static final int GAME_MODE_FIXED_TIME_PER_MOVE = 1;

  public static final int GAME_MODE_FIXED_TIME_PER_MOVES = 2;

  public int GAME_MODE = 2;

  public String GAME_MODE_DOC = "Game Mode";

  public int FIXED_DEPTH = 6;

  public String FIXED_DEPTH_DOC = "Fixd search depth (Game Mode 0)";

  public int FIXED_TIME_PER_MOVE = 10;

  public String FIXED_TIME_PER_MOVE_DOC = "Fixed time per move (Game Mode 1)";

  public int FIXED_TIME_PER_MOVES_SECONDS = 300;

  public String FIXED_TIME_PER_MOVES_SECONDS_DOC = "Time for N Moves (Game Mode 2)";

  public int FIXED_TIME_PER_MOVES_MOVE_COUNT = 40;

  public String FIXED_TIME_PER_MOVES_MOVE_COUNT_DOC = "Moves to do in N Seconds (Game Mode 2)";

  public double TIME_HOLE = 0.1;
  
  public String TIME_HOLE_DOC = "Time in Seconds to decrease from calculated move time";
  
  public int MAX_DEPTH = 30;

  public String MAX_DEPTH_DOC = "Maximal depth";

  public int MAX_QUIESCENCE_DEPTH = 10;

  public String MAX_QUIESCENCE_DEPTH_DOC = "Maximal quiescence search depth";

  @Override
  public EngineSettings clone() throws CloneNotSupportedException {
    EngineSettings result = (EngineSettings) super.clone();
    return result;
  }

  public EngineSettings(String fileName) throws NosSettingsException {
    this(fileName, false);
  }

  public EngineSettings(String fileName, boolean writeFirst) throws NosSettingsException {
    File fileToRead = new File(System.getProperty("user.home") + "/.tiffanys", fileName);

    if (writeFirst) {
      this.writeSettingsToXml(fileToRead);
    }

    // now load, (and write if needed).

    try {
      this.readSettingsFromXml(fileToRead);
    } catch (NosSettingsException e) {
      if (!writeFirst) {
        this.writeSettingsToXml(fileToRead);
      }
    }

  }

  public EngineSettings() {
    super();
  }

}
